/************************************************************************************
 * MONASH UNIVERSITY, Faculty of Information Technology, Clayton School of IT.      *   
 * Student Declaration for FIT1008 Submission. I Menghong Li, ID:22988319           *
 * declare that this submission is my own work and has not been copied from any     *
 * other source without attribution. I acknowledge that severe penalties exist      *
 * for any copying of code without attribution, including a fail mark for this prac *
 ************************************************************************************/

package prac1;
public class UsingApps{
/**
 * Using applications and find out the identifier of the most expensive application
 * 
 * @author             mli90
 * @since              28 July 2011
 * @input              none
 * @output             none
 * @knownBugs          none
 * @Constructor        UsingApps()
 * 
 * @publicMethods      long expensiveApp(App[] Apps)
 * 
 */
	public UsingApps() {
		
	}
	
	/**
	 * 
	 * @pre        Apps exist and has at least one element
	 * @post       the identifier of the application which has the max price is found and returned
	 * @complexity O(n) where n is the number of items in the array
	 * @param Apps an array of applications 
	 * @return     the identifier of the application which has the maximum price
	 */
	public long expensiveApp(App[] Apps){
		
		//Initialise the identifier and maxprice
		long identifier = Apps[0].getUniqueIdentifier();
		double maxPrice = Apps[0].getPrice();
		
		//For each application in this array
		for (App app : Apps) {
			// Printing all the information for each application
			System.out.println(app.toString());
			System.out.println();
			if(app.getPrice()>maxPrice){
				maxPrice = app.getPrice();
				identifier =app.getUniqueIdentifier();
			}
		}
		return identifier;
	}
	
	/**
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		App app1 = new App("app1", "Leo Li", 30);
		App app2 = new App("app2", "Leo", 31);
		App app3 = new App("app3", "Menghong Li", 32);
		App app4 = new App("app4", "Menghong", 33);
		App app5 = new App("app5", "Li", 33);
		
		// vote app1
		app1.vote(1.5);
		app1.vote(2.5);
		app1.vote(3.5);
		app1.vote(4.5);
		
		//vote app2
		app2.vote(2.5);
		app2.vote(3.5);
		app2.vote(4.5);
		app2.vote(3.5);
		
		//vote app3
		app3.vote(3.5);
		app3.vote(4.5);
		app3.vote(1.5);
		app3.vote(2);
		
		//vote app4
		app4.vote(1);
		app4.vote(2);
		app4.vote(3);
		app4.vote(4);
		
		//vote app5
		app5.vote(1.5);
		app5.vote(2);
		app5.vote(3.5);
		app5.vote(4);
		
		UsingApps ua = new UsingApps();
		App apps[]={app1, app2, app3, app4, app5};
		System.out.println("The identifier of the most expensive application is:"+ ua.expensiveApp(apps));
	}
	
}